package com.idp.biz.bpchannel.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.common.enums.CommonCode;
import com.common.model.PageModel;
import com.common.utils.ResourceUtil;
import com.idp.biz.bpchannel.service.BpChannelService;
import com.idp.biz.bpchannel.dao.BpChannelDao;
import com.idp.biz.bpchannel.entity.BpChannel;

/**
 * 热门频道service实现类
 * 
 * @author Stone 2019-06-29
 *
 */
@Service("bpChannelService")
public class BpChannelServiceImpl implements BpChannelService {

	@Autowired
	private BpChannelDao bpChannelDao;
	
	@Override
	public PageModel<BpChannel> findByPage(BpChannel bpChannel, PageModel<BpChannel> page) {
		PageHelper.offsetPage(page.getStart(), page.getLength());
		page.initData(bpChannelDao.findByPage(bpChannel));
		return page;
	}
	
	@Override
	public List<BpChannel> findBySearch(BpChannel bpChannel) {
		return bpChannelDao.find(bpChannel);
	}
	
	@Override
	public BpChannel getById(String id) {
		return bpChannelDao.getById(id);
	}

	@Override
	public void add(BpChannel bpChannel) {
		bpChannel.setId(ResourceUtil.getUUID());
		bpChannel.setSymbol(CommonCode.Y.getValue());
		bpChannelDao.add(bpChannel);
	}
	
	@Override
	public void update(BpChannel bpChannel) {
		bpChannelDao.updateNotNull(bpChannel);
//		bpChannelDao.update(bpChannel);
	}

	@Override
	public void delete(String ids) {
		List<String> idList = Arrays.asList(ids.split(","));
		bpChannelDao.batchDelete(idList);
	}
 	
}